package cn.wolfcode.trip.api.controller;

import cn.wolfcode.trip.core.domain.StrategyComment;
import cn.wolfcode.trip.core.service.IStrategyCommentService;
import cn.wolfcode.trip.core.util.JsonResult;
import cn.wolfcode.trip.core.util.RequriedLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 攻略评论资源控制器
 */
@RestController
@RequestMapping("strategyComments")
public class StrategyCommentController {

    @Autowired
    private IStrategyCommentService commentService;

    /**
     * 新增攻略评论
     * 1.资源路径 /strategyComments
     * 2.请求方式 post
     * 3.请求参数 评论对象 , 标签数组
     * 4.返回结果 JsonResult
     */
    @PostMapping
    @RequriedLogin
    public JsonResult save(StrategyComment comment, String[] tags){

        JsonResult json = new JsonResult();
        try {
            commentService.saveOrUpdate(comment, tags);
        } catch (Exception e) {
            e.printStackTrace();
            json.mark(e.getMessage());
        }
        return json;
    }

}
